<template>
	<view class="">
		<view class="tab"><lrTabs :tabs="tabs" @change="change"></lrTabs></view>
		<view v-if="activityList.length > 0">
			<view v-if="activityList.length > 0" v-for="(item, index) in activityList" :key="item.orderNo">
				<activity-order-list :orderObj="item"></activity-order-list>
			</view>
			
			<u-loadmore :status="loadingStatus" @loadmore="clickloadmore"></u-loadmore>
		</view>
		
		<u-empty v-if="activityList.length == 0" mode="order" marginTop="160"></u-empty>
	</view>
</template>

<script>
	import lrTabs from '../../components/activity/lr-tabs.vue'
	import activityOrderList from '../../components/activity/activity-orderList.vue'
	import {myOrderList,myOrderCount} from '../../common/api.js'
	export default {
		components: {
			lrTabs,
			activityOrderList
		},
		data() {
			return {
				pageNo:1,
				loadingStatus: 'loading',
				activityStatus: 1,
				tabs: [
					{
						status:1,
						code : 0,
						value : '可使用'
					},
					{
						status:2,
						code : 0,
						value : '已使用'
					},
					{
						status:3,
						code : 0,
						value : '已过期'
					},
					{
						status:5,
						code : 0,
						value : '已退款'
					}
				],
				activityList: []
			}
		},
		methods: {
			getOrderList() {
			  myOrderList({
					pageNo: this.pageNo,
					memberNo: this.$store.state.user.userInfo.customerId,
					activityStatus: this.activityStatus
				}).then(res => {
					if (this.pageNo == 1) {
						this.activityList = [];
						this.pageNo++;
						// uni.stopPullDownRefresh();
					
						this.loadingStatus = 'loadmore';
					} else {
						if (!uni.$u.test.isEmpty(res)) {
							this.pageNo++;
					
							this.loadingStatus = 'loadmore';
						} else {
					
							this.loadingStatus = 'nomore';
						}
					}
					
					if (!uni.$u.test.isEmpty(res)) {
						this.activityList = this.activityList.concat(res);
					}
				})
			},
			myOrderCount() {
			  myOrderCount(this.$store.state.user.userInfo.customerId).then(res => {
					let data = res[0];
					this.tabs[0].code = data.noUse
					this.tabs[1].code = data.alreadyUse
					this.tabs[2].code = data.alreadyOverdue
					this.tabs[3].code = data.alreadyRefund
				})
			},
			change(index) {
				let item = this.tabs[index];
				this.pageNo = 1;
				this.activityStatus =  item.status;
				this.getOrderList();
				
			},
			clickloadmore() {
				this.getOrderList();
				this.showloading = true;
				this.loadingStatus = 'loading';
			}
		},
		onLoad() {
			this.getOrderList();
			this.myOrderCount();
		},
		onPullDownRefresh() {
			this.pageNo = 1;
			this.getOrderList();
		},
		
		onReachBottom() {		
			this.getOrderList();
			this.showloading = true;
			this.loadingStatus = 'loading';
		}
	}
</script>

<style lang="scss" scoped>
	.tab {
		position: sticky;
		top: 0;
		background-color: #F5F5F5;
		z-index: 2;
	}
</style>
